﻿using System;
using UnityEngine;

namespace AI
{
	// Token: 0x020001EE RID: 494
	public class AIController : MonoBehaviour
	{
		// Token: 0x06000A75 RID: 2677 RVA: 0x0005AA99 File Offset: 0x00058C99
		private void Update()
		{
			this.Execute();
		}

		// Token: 0x06000A76 RID: 2678 RVA: 0x0005AAA1 File Offset: 0x00058CA1
		private void FixedUpdate()
		{
			this.FixedExecute();
		}

		// Token: 0x06000A77 RID: 2679 RVA: 0x0005AAAC File Offset: 0x00058CAC
		public void Initialize(Humanoid entity)
		{
			this.agent = entity;
			if (this.agent.isMicro)
			{
				this.decisionMaker = new MicroDecisionMaker(this.agent);
			}
			else if (this.agent.isGiantess)
			{
				this.decisionMaker = new GTSDecisionMaker(this.agent);
			}
			this.behaviorController = new BehaviorController(this.agent);
			this.actionManager = this.agent.actionManager;
			this.mentalState = new MentalState(this.agent);
		}

		// Token: 0x06000A78 RID: 2680 RVA: 0x0005AB3A File Offset: 0x00058D3A
		public void EnableAI()
		{
			if (!this.IsEnabled())
			{
				this.ai = true;
			}
		}

		// Token: 0x06000A79 RID: 2681 RVA: 0x0005AB4E File Offset: 0x00058D4E
		public bool IsEnabled()
		{
			return this.ai;
		}

		// Token: 0x06000A7A RID: 2682 RVA: 0x0005AB56 File Offset: 0x00058D56
		public void DisableAI()
		{
			if (this.IsEnabled())
			{
				this.ai = false;
				if (this.behaviorController != null && !this.behaviorController.IsIdle())
				{
					this.behaviorController.StopMainBehavior();
				}
			}
		}

		// Token: 0x06000A7B RID: 2683 RVA: 0x0005AB90 File Offset: 0x00058D90
		public void Execute()
		{
			if (BehaviorLists.Instance == null)
			{
				return;
			}
			if (this.ai && this.decisionMaker != null)
			{
				this.decisionMaker.Execute();
			}
			if (this.behaviorController != null)
			{
				this.behaviorController.Execute();
			}
			if (this.actionManager != null)
			{
				this.actionManager.Execute();
			}
		}

		// Token: 0x06000A7C RID: 2684 RVA: 0x0005ABFB File Offset: 0x00058DFB
		public void FixedExecute()
		{
			if (BehaviorLists.Instance == null)
			{
				return;
			}
			if (this.behaviorController != null)
			{
				this.behaviorController.FixedExecute();
			}
			if (this.actionManager != null)
			{
				this.actionManager.FixedExecute();
			}
		}

		// Token: 0x06000A7D RID: 2685 RVA: 0x0005AC3C File Offset: 0x00058E3C
		public void ImmediateCommand(IBehavior newBehavior, EntityBase target, Vector3 cursorPoint)
		{
			BehaviorInstruction behaviorInstruction = default(BehaviorInstruction);
			behaviorInstruction.newBehavior = newBehavior;
			behaviorInstruction.target = target;
			behaviorInstruction.cursorPoint = cursorPoint;
			this.behaviorController.ChangeBehavior(behaviorInstruction);
		}

		// Token: 0x06000A7E RID: 2686 RVA: 0x0005AC78 File Offset: 0x00058E78
		public void ScheduleCommand(IBehavior newBehavior, EntityBase target, Vector3 cursorPoint)
		{
			BehaviorInstruction behaviorInstruction = default(BehaviorInstruction);
			behaviorInstruction.newBehavior = newBehavior;
			behaviorInstruction.target = target;
			behaviorInstruction.cursorPoint = cursorPoint;
			this.behaviorController.ScheduleBehavior(behaviorInstruction);
		}

		// Token: 0x06000A7F RID: 2687 RVA: 0x0005ACB1 File Offset: 0x00058EB1
		public bool IsIdle()
		{
			return this.behaviorController.IsIdle();
		}

		// Token: 0x06000A80 RID: 2688 RVA: 0x0005ACBE File Offset: 0x00058EBE
		private void OnEnable()
		{
			if (this.behaviorController != null)
			{
				this.behaviorController.StopMainBehavior();
			}
		}

		// Token: 0x06000A81 RID: 2689 RVA: 0x0005ACD6 File Offset: 0x00058ED6
		private void OnDrawGizmos()
		{
			Gizmos.color = Color.blue;
			Gizmos.DrawWireSphere(this.agent.transform.position, 1f);
		}

		// Token: 0x04000FB0 RID: 4016
		private Humanoid agent;

		// Token: 0x04000FB1 RID: 4017
		public MentalState mentalState;

		// Token: 0x04000FB2 RID: 4018
		public DecisionMaker decisionMaker;

		// Token: 0x04000FB3 RID: 4019
		public BehaviorController behaviorController;

		// Token: 0x04000FB4 RID: 4020
		public ActionController actionManager;

		// Token: 0x04000FB5 RID: 4021
		private bool ai;
	}
}
